<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
    clear: left;
  }
  .sale-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .sale-btn-export {
    float: left;
    margin-bottom: 10px;
    /* margin-top: -46px; */
    /* float: right; */
  }
  .sale-tag {
    width: 180px;
    height: 50px;
    font-size: 13px;
    text-align: center;
    line-height: 50px;
    margin-left: 3px;
  }
  .cloud-sale-card {
    background: url(../../../assets/images/cloudSale.png) no-repeat;
    background-size:100% 100%;
  }
  .all-sale-card {
    background: url(../../../assets/images/allSale.png) no-repeat;
    background-size:100% 100%;
  }
  .month-sale-card {
    background: url(../../../assets/images/monthSale.png) no-repeat;
    background-size:100% 100%;
  }
  .customer-count-card {
    background: url(../../../assets/images/customerCount.png) no-repeat;
    background-size:100% 100%;
  }
  .come-count-card {
    background: url(../../../assets/images/comeCount.png) no-repeat;
    background-size:100% 100%;
  }
  .sign-count-card {
    background: url(../../../assets/images/signCount.png) no-repeat;
    background-size:100% 100%;
  }
  .container {
    clear: both;
    display: flex;
    justify-content: space-around;
    margin-bottom:10px;
  }
  .sale-card-text {
    /* width: 120px; */
    /* text-align: center; */
    margin-left: 13%;
    margin-top: 25px;
    /* left: 55%; */
    color: #fff;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>销售列表</span>
    </div>
    <div class="line"></div>
    <sale-form
      class="sale-form"
      @on-success-valid="handleSubmit">
    </sale-form>
    <!-- <Button
      icon="md-add"
      type="primary"
      @click="handleClick">
      添加任务
    </Button> -->
    <sale-drawer
      :row="row">
    </sale-drawer>
    <!-- <task-list-confirm-modal
      :confirmData="confirmData"
      @confirm-task-list-valid="handleConfirm">
    </task-list-confirm-modal> -->
    <!-- <div style="clear: left">
      <div style="font-size: 15px; margin-left: 10px;">销售汇总数据：</div>
      <div v-show="saleList" style="margin-left: 130px; margin-top: -28px;">
        <Tag color="blue" class="sale-tag">云销售人数：{{ saleView && saleView.salenum? saleView.salenum : '0' }}</Tag>
        <Tag color="blue" class="sale-tag">总销售业绩：{{saleView && saleView.aprice ? saleView.aprice : '0'}}</Tag>
        <Tag color="blue" class="sale-tag">当月销售业绩：{{saleView && saleView.mprice ? saleView.mprice : '0'}}</Tag>
        <Tag color="blue" class="sale-tag">客户人数：{{saleView && saleView.allnum ? saleView.allnum : '0'}}</Tag>
        <Tag color="blue" class="sale-tag">到店人数：{{saleView && saleView.cnum ? saleView.cnum : '0'}}</Tag>
        <Tag color="blue" class="sale-tag">签约人数：{{saleView && saleView.onum ? saleView.onum : '0'}}</Tag>
      </div>
    </div> -->
    <div class="container">
      <div class="cloud-sale-card" style="width: 246px; height: 122px">
        <div class="sale-card-text">
          <span style="font-size: 17px;">
          云销售人数(人)
          </span>
          <div style="font-size: 30px;">{{saleView && saleView.salenum? saleView.salenum : '0'}}</div>
        </div>
      </div>
      <div class="all-sale-card" style="width: 246px; height: 122px">
        <div class="sale-card-text">
          <span style="font-size: 17px;">
          总销售业绩(元)
          </span>
          <div style="font-size: 30px;">{{saleView && saleView.aprice ? saleView.aprice : '0'}}</div>
        </div>
      </div>
      <div class="month-sale-card" style="width: 246px; height: 122px">
        <div class="sale-card-text">
          <span style="font-size: 17px;">
          当月销售业绩(元)
          </span>
          <div style="font-size: 30px;">{{saleView && saleView.mprice ? saleView.mprice : '0'}}</div>
        </div>
      </div>
      <div class="customer-count-card" style="width: 246px; height: 122px">
        <div class="sale-card-text">
          <span style="font-size: 17px;">
          意向人数(人)
          </span>
          <div style="font-size: 30px;">{{saleView && saleView.allnum ? saleView.allnum : '0'}}</div>
        </div>
      </div>
      <div class="come-count-card" style="width: 246px; height: 122px">
        <div class="sale-card-text">
          <span style="font-size: 17px;">
          到店人数(人)
          </span>
          <div style="font-size: 30px;">{{saleView && saleView.cnum ? saleView.cnum : '0'}}</div>
        </div>
      </div>
      <div class="sign-count-card" style="width: 246px; height: 122px">
        <div class="sale-card-text">
          <span style="font-size: 17px;">
          签约人数(人)
          </span>
          <div style="font-size: 30px;">{{saleView && saleView.onum ? saleView.onum : '0'}}</div>
        </div>
      </div>
    </div>
    <btn-export :tableData="saleList" :tableTitle="columns" :title="title" class="sale-btn-export"></btn-export>
    <Table
      class="table"
      :loading="loading"
      :columns="columns"
      :data="historyData"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import SaleForm from '_c/sale-form'
import BtnExport from '_c/btn-export'
import SaleDrawer from '_c/sale-drawer'
import TaskListConfirmModal from '_c/task-list-confirm-modal'
import TablePage from '_c/table-page'
export default {
  components: {
    SaleForm,
    SaleDrawer,
    TaskListConfirmModal,
    TablePage,
    BtnExport
  },
  data () {
    return {
      page: 1,
      title: '销售管理销售列表',
      loading: true,
      rows: 20,
      confirmData: {},
      playload: null,
      postData: {},
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '云销售姓名',
          key: 'coludname',
          width: 160,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.coludname ? params.row.coludname : '-')
          }
        },
        {
          title: '推荐销售',
          key: 'mname',
          width: 160,
          align: 'center'
        },
        {
          title: '加入时间',
          key: 'ctime',
          width: 200,
          align: 'center'
        },
        {
          title: '总销售金额',
          key: 'hisprice',
          width: 160,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.hisprice ? params.row.hisprice : '-')
          }
        },
        {
          title: '当月销售金额',
          key: 'mprice',
          width: 166,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.mprice ? params.row.mprice : '-')
          }
        },
        {
          title: '客户人数',
          key: 'acn',
          width: 160,
          align: 'center'
        },
        {
          title: '到店人数',
          key: 'cnum',
          width: 160,
          align: 'center'
        },
        {
          title: '签约人数',
          key: 'onum',
          width: 160,
          align: 'center'
        },
        {
          title: '操作',
          key: 'cz',
          minWidth: 183,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small',
                  ghost: 'ghost'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.handleClick(params.row.id, params.row)
                  }
                }
              }, '详情')
            ])
          }
        }
      ]
    }
  },
  computed: {
    ...mapState({
      saleList: state => state.sale.saleList,
      saleView: state => state.sale.saleView,
      saleSumData: state => state.sale.saleSumData,
      dataCount: state => state.sale.saleDataCount,
      historyData: state => state.sale.saleHistoryData,
      pageSize: state => state.sale.salePageSize,
      row: state => state.sale.row
    })
  },
  methods: {
    ...mapActions([
      'getSaleList',
      'getSaleViewData',
      'getSaleDrawerList',
      'getNameList',
      'getSaleCurrentRow',
      'editSaleData',
      'updateSaleDrawerState',
      'updateConfirmModalState',
      'changeSalePage',
      'changeSalePageSize'
    ]),
    handleSubmit (playload) {
      this.loading = true
      // console.log(playload)
      this.playload = playload
      this.getSaleList({
        ...playload,
        rows: this.rows
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    handleClick (id, row) {
      // console.log(row)
      let newRow = {}
      this.id = id
      if (row) {
        newRow = Object.assign({}, row)
      }
      this.getSaleDrawerList({ uid: row.id ? row.id : -1 })
      this.getSaleCurrentRow(newRow)
      this.updateSaleDrawerState(true)
    },
    changePage (index) {
      this.loading = true
      this.page = index
      this.changeSalePage(index)
      this.getSaleList({
        page: index,
        rows: this.rows,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePageSize (value) {
      this.loading = true
      this.rows = value
      this.changeSalePageSize(value)
      this.changePage(this.page)
      this.getSaleList({
        rows: value,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getSaleList({}).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
    this.getNameList({})
    this.getSaleViewData({})
  }
}
</script>
